// the code pattern will be default and the pattern will be mentioned in the user manual
// we are not integrating a function to set a new code of choice

// pattern is >> LEFT-DOWN -RIGHT-UP

#include "easybutterfly.h"


#define btn_center !(PINB & (1<<4))
#define btn_up !(PINB & (1<<6))
#define btn_down !(PINB & (1<<7))
#define btn_left !(PINE & (1<<2))
#define btn_right !(PINE & (1<<3))

int pattern()
{	
	int patt = 1;
	int cntr = 1;
	while(patt)
	{	
		switch(cntr)
		{
			case 1:
			if(btn_left)
			{
				while(btn_left);
				cntr = 2;
			}
			else if(btn_right || btn_down || btn_up)
			{
				cntr = 5;
			}
			else{}
			break;
			
			case 2:
			if(btn_down)
			{
				while(btn_down);
				cntr = 3;
			}
			else if(btn_right || btn_left || btn_up)
			{
				cntr = 5;
			}
			break;
			
			case 3:
			if(btn_right)
			{
				while(btn_right);
				cntr = 3;
			}
			else if(btn_down || btn_left || btn_up)
			{
				cntr = 5;
			}
			break;
			
			case 4:
				if(btn_up)
				{
					while(btn_up);
				}
				else if(btn_down || btn_left || btn_up)
				{
					cntr = 5;
				}
				break;
			
			case 5:
				patt = 0;
				break;
				
			default:
				break;
				
			
		}
	}
	return patt;
}


